package com.tuling.code.jvm.classloader;

public class ClassLoaderTest {
	public static void main(String[] args) throws Exception {
		
		//福类加载器被设置成了AppClassLoader,加载classpath下面的所有class文件和jar包。
		//父类优先加载到了Demo.class  。s所以寻找到的是classpath下的Demo
		MyClassLoader p1 = new MyClassLoader("Zhangfei", "D:/tmp/");
		
		//如果将父类加载器设置成null,那么它的父类加载器就被设置成了Bootstrap classLoader,
		//而BootStrap ClassLoader只会加载到jdk lib目录下的class  jar包，那么父类加载器找不到
		//就回到子类加载器中去寻找（findClass）
		MyClassLoader p2 = new MyClassLoader("Zhangfei", "D:/tmp/",null);
		
		//设置父类加载器
		MyClassLoader loader = new MyClassLoader("WuKong", "/",p1);
		Class<?> demo = loader.loadClass("com.tuling.code.jvm.classloader.Demo");
		demo.newInstance();
		
		
		loader = new MyClassLoader("WuKong", "/",p2);
		demo = loader.loadClass("com.tuling.code.jvm.classloader.Demo");
		demo.newInstance();
	}
}
